﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;

namespace Ashlen.Utility.NewsService
{
    /// <summary>
    ///  The service host can be run in Windows service mode or console mode.
    ///  To run in console mode, pass in the argument /console at the command line.
    /// </summary>
    /// <remarks>
    /// Author: Shailen Sukul
    /// Date: 08 Oct 2008
    /// </remarks>
    static class Program
    {
        /// <summary>
        /// The entry point
        /// </summary>
        static void Main(string[] args) {
            try {
                if (args != null && args.Length > 0 && args[0].Trim().ToLower() == "/console") {
                    Log.LogEvent(System.Diagnostics.EventLogEntryType.Information, "Starting in console mode.");
                    Console.WriteLine("Starting service...");
                    NewsFeedServiceHost host = new NewsFeedServiceHost();
                    host.StartService(null);
                    Console.WriteLine("Service started. Press ENTER to exit.");
                    Console.ReadLine();
                    Console.WriteLine("Stopping service...");
                    host.StopService();
                }
                else {
                    Log.LogEvent(System.Diagnostics.EventLogEntryType.Information, "Starting in Windows Service mode.");
                    ServiceBase[] ServicesToRun;
                    ServicesToRun = new ServiceBase[] { new NewsFeedServiceHost() };
                    ServiceBase.Run(ServicesToRun);
                }
            }
            catch (Exception ex) {
                ConsoleColor oldColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.ToString());
                Console.ForegroundColor = oldColor;
            }
        }
    }
}
